{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals())}}
{{extend 'layout.html'}}

{{if 'message' in globals():}}
<h3>{{=message}}</h3>
{{pass}}

<!--
SOCKET.IO
-->
<script src="http://127.0.0.1:8080/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
//var baseUrl = 'http://88.222.149.115:8080'
var baseUrl = 'http://127.0.0.1:8080'
var socket = io.connect(baseUrl);
//console.log(socket.id);
console.log(window.location.pathname.substr(1));


var userId={{=playerID}};
var playerName = "{{=player_name}}";
//var matchId;
//http://88.222.149.115:8080/ticktacktoe/1/creator/1
socket.on('connect', function () {
	console.log(this.socket.sessionid);
	/*path = window.location.pathname.substr(1).split('/')
	if(path.length == 4) {
		matchId = parseInt(path[1])
		action = path[2]
		userId = parseInt(path[3])
		socket.emit('connect', {'matchId':matchId, 'userId':userId, 'action':action});
	}*/
    //socket.emit('before_game', {'matchId':matchId, 'userId':userId, 'action':action});
	//console.log('userId', userId, 'matchId', matchId);
    socket.emit('introduce', { 'userId':userId});
	console.log('CONNECT: userId', userId);
});

socket.on('broadcast', function (data) {
	console.log('broadcast get', data);
});

socket.on('pong', function (data) {
	console.log('pong', data);
});

socket.on('disconnected', function (data) {
	$('#info').show().removeClass().addClass('disconnected').html('Your partner disconnected');
	console.log('disconnected', data);
});
socket.on('waiting', function (data) {
	$('#info').show().removeClass().addClass('waiting').html('Waiting for partner to join');
	console.log('waiting', data);
});
        
</script>

{{=INPUT(_value="Hi", _type="button", _onclick="socket.emit('ping', {}); console.log('ping');") }}
{{=INPUT(_value="Broadcast", _type="button", _onclick="socket.emit('broadcast', {playerName:playerName}); console.log('broadcast send');") }}

{{block right_sidebar}}
{{=A(T("Administrative Interface"), _href=URL('admin','default','index'), _class='btn',
     _style='margin-top: 1em;')}}
<h6>{{=T("Don't know what to do?")}}</h6>
<ul>
  <li>{{=A(T("Online examples"), _href=URL('examples','default','index'))}}</li>
  <li><a href="http://web2py.com">web2py.com</a></li>
  <li><a href="http://web2py.com/book">{{=T('Documentation')}}</a></li>
</ul>
{{end}}
